package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TogetherContent;
import cn.wolfcode.trip.base.domain.TogetherTrip;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.TogetherContentMapper;
import cn.wolfcode.trip.base.mapper.TogetherTripMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TogetherTripQueryObject;
import cn.wolfcode.trip.base.service.ITogetherTripService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TogetherTripServiceImpl implements ITogetherTripService {
    
    @Autowired
    private TogetherTripMapper togetherTripMapper;
    @Autowired
    private TogetherContentMapper contentMapper;
    @Override
    public PageInfo<TogetherTrip> query(TogetherTripQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), true, false, null);
        List<TogetherTrip> list = togetherTripMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(TogetherTrip togetherTrip) {

    }

    @Override
    public TogetherTrip getById(Long id) {
        return togetherTripMapper.selectByPrimaryKey(id);
    }

    @Override
    public void save(TogetherTrip togetherTrip) {
        togetherTripMapper.insert(togetherTrip);
        TogetherContent content = togetherTrip.getContent();
        content.setId(togetherTrip.getId());
        contentMapper.insert(content);
    }

    @Override
    public TogetherTrip selectTogetherByUserId(Long togetherId, Long userId) {
        return togetherTripMapper.selectTogetherByUserId(togetherId,userId);
    }

    @Override
    public void insertUserAndTogetherRelation(Long togetherId, Long userId) {
        togetherTripMapper.insertUserAndTogetherRelation(togetherId,userId);
    }

    @Override
    public void deleteTogetherAndUserRelation(Long togetherId, Long userId) {
        togetherTripMapper.deleteTogetherAndUserRelation(togetherId,userId);
    }
    @Override
    public void deleteTogetherAndUserRelation1(Long togetherId, Long userId) {
        togetherTripMapper.deleteTogetherAndUserRelation1(togetherId,userId);
    }

    @Override
    public List<User> getUsersByTogetherId(Long togetherId) {
        return togetherTripMapper.getUsersByTogetherId(togetherId);
    }

    @Override
    public void updateApplyNumById(Long id, Integer applyNum) {
        togetherTripMapper.updateApplyNumById(id,applyNum);
    }
    @Override
    public void updateCollectionNumById(Long id, Integer collectionNum) {
        togetherTripMapper.updateCollectionNumById(id,collectionNum);
    }

    @Override
    public List<User> getUsersByTogetherCollectionId(Long togetherId) {
        return togetherTripMapper.getUsersByTogetherCollectionId(togetherId);

    }

    @Override
    public PageInfo selectAppTogetherTrips(TogetherTripQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), true, false, null);
        List<TogetherTrip> list = togetherTripMapper.selectAppTogetherTrips(qo);
        return new PageInfo(list);
    }

    @Override
    public PageInfo selectColTogetherTrips(TogetherTripQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), true, false, null);
        List<TogetherTrip> list = togetherTripMapper.selectColTogetherTrips(qo);
        return new PageInfo(list);
    }


    @Override
    public TogetherTrip selectCollectionByUserId(Long togetherId, Long userId) {
        return togetherTripMapper.selectCollectionByUserId(togetherId,userId);
    }

    @Override
    public void insertUserAndTogetherRelation1(Long togetherId, Long userId) {
        togetherTripMapper.insertUserAndTogetherRelation1(togetherId,userId);

    }
}
